import Vue from 'vue'
import VeeValidate, {Validator} from 'vee-validate'
import zh from 'vee-validate/dist/locale/zh_CN';//引入中文文件

const config = {
  locale: 'zh_CN'
};

Vue.use(VeeValidate,config);

// 自定义validate
const dictionary = {
  zh_CN: {
    messages: {
      email:'请输入正确的邮箱格式',
      required: function(field){return field + "不能为空"},
      numeric:'只能输入数字',
      confirmed:'两次密码需要一致',
    },
    attributes:{
      email:'邮箱',
      password:'密码',
      name: '账号',
      phone: '手机号码',
      code:'验证码',
    }
  }
};

Validator.extend('mobile', {
  getMessage:'请输入格式正确的电话号码',
  validate: function (value) {
    return /^1[345789]\d{9}$/.test(value)
  }
});

Validator.extend('password', {
  getMessage:'请输入至少六位字符的密码',
  validate:function (value) {
    return value.length >= 6
  }
});

Validator.extend('idcard', {
  getMessage:'请输入格式正确的身份证号码',
  validate:function (value) {
    return /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value)
  }
});

Validator.extend('money', {
  getMessage:'金额的输入格式不正确,请确认!',
  validate:function (value) {
    return /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/.test(value)&&value!=0
  }
});

Validator.localize(dictionary);
// 配置中文
Validator.localize(zh);

